package forces;

import masses.Mass;


/**
 * This class represents a viscous drag force which applies a resistive force on
 * masses proportional to their velocity.
 * 
 * @author Jenni Mercado
 */

public class Viscosity extends Force {
    private double myScalar;

    private double myDefaultScalar = .15;

    /**
     * Creates Viscous force based on mass' current velocity.
     * 
     * @param scalar scales magnitude based on mass' current velocity
     */
    public Viscosity (double scalar) {
        super();
        myScalar = scalar;
    }

    public Viscosity (Mass mass) {
        super();
        myScalar = myDefaultScalar;
    }

    @Override
    public void update (Mass mass) {
        double speed = mass.getVelocity().getMagnitude();
        double direction = mass.getVelocity().getDirection();

        // / set the Force opposite the Mass's direction
        this.setDirection(direction);
        this.negate();
        // scale it by the Mass's velocity
        this.setMagnitude(speed * myScalar);
    }
}
